package com.lengyu.vxminiprogram.common;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * Created By liuyu On 2019/12/06
 */
@Data
public class BaseEntityForMongo implements Serializable {
    @ExcelIgnore
    private String id;

    @DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time", fill = FieldFill.INSERT) // 新增执行
    @ExcelIgnore
    private Date createTime;

    @DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) // 新增和更新执行
    @ExcelIgnore
    private Date updateTime;
    @ExcelIgnore
    private String createDingId;
    @ExcelIgnore
    private String updateDingId;

    public void prepareForInsert(){
        this.id = UUID.randomUUID().toString().replaceAll("-","");
        this.createTime = new Date(System.currentTimeMillis());
        this.updateTime = new Date(System.currentTimeMillis());
    }


    public void prepareForUpdate(){
        this.updateTime = new Date(System.currentTimeMillis());
    }
}
